//
//  SysMsgTableCell.m
//  MiaoTu
//
//  Created by dllo on 16/9/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "SysMsgTableCell.h"
#import "MessageItem.h"
#import "Content.h"
#import "NSDate+CompareDate.h"

@interface SysMsgTableCell ()
@property (nonatomic, strong) UIView *redView;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@end

@implementation SysMsgTableCell

- (void)setMessageItem:(MessageItem *)messageItem {
    _messageItem = messageItem;
    
    if (_messageItem.Status == 0) {
        _redView.backgroundColor = [UIColor redColor];
    } else {
        _redView.backgroundColor = [UIColor clearColor];
    }
    _titleLabel.text = _messageItem.Title;
    [_titleLabel sizeToFit];
    
    NSString *intervalString = [NSDate intervalStringFromDateString:_messageItem.Created];
    _timeLabel.text = intervalString;
    [_timeLabel sizeToFit];
    
    _contentLabel.text = _messageItem.Content.Content;
    [_contentLabel sizeToFit];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initLayout];
    }
    return self;
}

- (void)initLayout {
    _rootLayout = [MyRelativeLayout new];
    _rootLayout.padding = UIEdgeInsetsMake(10, 10, 10, 10);
    _rootLayout.widthDime.equalTo(self.contentView.widthDime);
    _rootLayout.wrapContentHeight = YES;
    [self.contentView addSubview:_rootLayout];
    
    _redView = [UIView new];
    _redView.topPos.equalTo(_rootLayout.topPos).offset(10);
    _redView.leftPos.equalTo(_rootLayout.leftPos);
    _redView.widthDime.equalTo(@5);
    _redView.heightDime.equalTo(@5);
    [_rootLayout addSubview:_redView];
    
    _titleLabel = [UILabel new];
    _titleLabel.centerYPos.equalTo(_redView.centerYPos);
    _titleLabel.leftPos.equalTo(_redView.rightPos).offset(10);
    _titleLabel.widthDime.equalTo(@300);
    [_rootLayout addSubview:_titleLabel];
    _titleLabel.font = [UIFont systemFontOfSize:19.0];
    
    _timeLabel = [UILabel new];
    _timeLabel.rightPos.equalTo(_rootLayout.rightPos);
    _timeLabel.centerYPos.equalTo(_titleLabel.centerYPos);
    [_rootLayout addSubview:_timeLabel];
    _timeLabel.font = [UIFont systemFontOfSize:16.f];
    _timeLabel.textColor = [UIColor colorWithWhite:0.682 alpha:1.000];
    
    _contentLabel = [UILabel new];
    _contentLabel.leftPos.equalTo(_titleLabel.leftPos);
    _contentLabel.topPos.equalTo(_timeLabel.bottomPos).offset(10);
    _contentLabel.rightPos.equalTo(_rootLayout.rightPos).offset(10);
    _contentLabel.flexedHeight = YES;
    _contentLabel.numberOfLines = 0;
    [_rootLayout addSubview:_contentLabel];
    _contentLabel.font = [UIFont systemFontOfSize:16.f];
    _contentLabel.textColor = [UIColor colorWithWhite:0.682 alpha:1.000];
    
}

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
